import java.util.*;


public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
class PalindromeList {
    public boolean chkPalindrome(ListNode head) {
        // write code here
        if(head == null){
            return true;
        }
        ListNode fast = head;
        ListNode slow = head;
        while(fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;
        }

        ListNode cur = slow.next;

        while(cur != null){
            ListNode curNext = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curNext;
        }

        while(head != slow){
            if(slow.val == head.val){
                slow = slow.next;
                head = head.next;
                if(head.next == slow){
                    return true;
                }
            }else{
                return false;
            }
        }
        return true;
    }
}
